# -*- coding: utf-8 -*-
"""
Some utilities to make Renyare work with features from Werkzeug project
"""
from werkzeug import BaseResponse
from .wsgi.error import RenyareError
from .xml.xslt import combine_templates, add_template

class XmlResponse(BaseResponse):
    """
    Accepts parsed XML data as response instead of text string
    Also prepares the response to be parsed with xslt proxy
    """
    def __init__(self, xml, **kwargs):
        self.xml = xml
        BaseResponse.__init__(self, **kwargs)

    def __call__(self, environ, start_response):
        combine_templates(environ)
        if not 'renyare.xml_response' in environ:
            environ['renyare.xml_response'] = self.xml
        return BaseResponse.__call__(self, environ, start_response)
